package com.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.dao.BookDao;
import com.entity.Book;
@Repository
public class BookDaoImpl extends BaseDaoImpl implements BookDao {

	@Override
	public Book getBook(String hql) {
		return (Book) getSession().createQuery(hql).uniqueResult();
	}

	@Override
	public Book getBook(int id) {
		return (Book) getSession().get(Book.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Book> getBooks(String hql) {
		return getSession().createQuery(hql).list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Book> getBooks(int start, int length) {
		String hql="from Book order by id asc";
		Query query=this.getSession().createQuery(hql);
		query.setFirstResult(start);
		query.setMaxResults(length);
		return query.list();
	}

}
